<?php
$functionListStr = Yii::t('BWeSport','Function list');
$bookableListStr = Yii::t('BWeSport','Bookable List');
$bookableContentStr = Yii::t('BWeSport','Bookable Content');
$bookingInformationStr = Yii::t('BWeSport','Booking Information');
$courtInformatinStr = Yii::t('BWeSport','Court Informatin');
$timeSetUpStr = Yii::t('BWeSport','Time Set Up');
$otherSetUpStr = Yii::t('BWeSport','Other Set Up');
$saveStr = Yii::t('BWeSport','Save');
/*
  if (!isset($bookableId) || $bookableId == NULL || (is_numeric($bookableId) && $bookableId <= 0)) {
  $event = new BWEvent($eventId);
  $messageList = $event->getMessageManager()->getMessageList();
  $count = 0;
  if (is_array($messageList)) {
  $count = count($messageList);
  }
  //populate new bookableId
  $bookableId = $count++;
  }
 * 
 */
$model = new BDynamicFormModel();
$modelClass = get_class($model);
$screen = Blyn::app()->getUIManager()->getCurrentScreen();
$url = $control->getAjaxLinkUrl('saveBookable', NULL, array(
    'bookableId' => $bookableId,
    'eventId' => $eventId,
    'postModel' => $modelClass));
$updateId = $control->getAjaxContainerId();
?>

<script type="text/javascript">
// this script for collecting the form data and pass to the controller action and doing the on success validations
    function saveBookable() {

        var formData = new FormData($("#message-form")[0]);
        //var formElement = document.getElementById("message-form");
        //var formData = new FormData(formElement);

        $.ajax({
            url: '<?php echo $url; ?>',
            type: 'POST',
            data: formData,
            datatype: 'json',
            // async: false,
            beforeSend: function() {
                $("#ajax-loaderdiv").show();
            },
            success: function(html) {
                // on success do some validation or refresh the content div to display the uploaded images 
                jQuery("#<?php echo $updateId; ?>").html(html);
                //alert(data);
            },
            complete: function() {
                $("#ajax-loaderdiv").hide();
            },
            error: function() {
                alert("There may a error on uploading. Try again later");
            },
            cache: false,
            contentType: false,
            processData: false
        });

        return false;
    }
</script>
<?php
$form = $this->beginWidget('CActiveForm', array(
    "id" => "message-form",
    'enableAjaxValidation' => FALSE,
    'htmlOptions' => array('enctype' => 'multipart/form-data'),
        ));
?>

<legend>
    <h4><?php echo $control->getAjaxLink(array('name' => $functionListStr, 'id' => 'showEventList')); ?>\

        <?php
        echo $control->getAjaxLink(array('name' => $bookableListStr, 'id' => 'showBookableList'), array(
            'eventId' => $eventId));
        ?>\
        <?php echo $bookableContentStr; ?>
    </h4>
</legend>

<div class="tabbable tabs-right" style="margin-top: 15px;"> <!-- Only required for left/right tabs -->
    <ul class="nav nav-tabs" style="margin-bottom: 15px">
        <li class="active"><a href="#tab1" data-toggle="tab"><?php echo $bookingInformationStr;?></a></li>
        <li class=""><a href="#tab2" data-toggle="tab"><?php echo $courtInformatinStr;?></a></li>
        <li class=""><a href="#tab3" data-toggle="tab"><?php echo $timeSetUpStr;?></a></li>
        <li class=""><a href="#tab4" data-toggle="tab"><?php echo '价格调整';?></a></li>
        <li class=""><a href="#tab5" data-toggle="tab"><?php echo $otherSetUpStr;?></a></li>
    </ul>
    <div class="tab-content">       
        <div class="tab-pane active" id="tab1" style="min-height: 380px;margin-right:2px;">                
            <?php
            $control->renderView('bookable_add_info', array(
                'eventId' => $eventId,
                'bookableId' => $bookableId,
                'model' => $model,
                'form' => $form
            ));
            ?>  
        </div>
        <div class="tab-pane" id="tab2" style="min-height: 380px;margin-right:2px;">                
            <?php
            $control0 = new BUIControl('addCourt');
            $data = array(
                'eventId' => $eventId,
                'bookableId' => $bookableId,
                'model' => $model,
                'form' => $form
            );
            $control0->addRenderView('courtList', 'bookable_add_courtList', $data);
            $control0->render();
            ?>  
        </div>

        <div class="tab-pane" id="tab3" style="min-height: 380px;margin-right:2px;">                
            <?php
            $control1 = new BUIControl('addTimeSlot');
            $control1->addRenderView('addTimeSlot', 'bookable_add_timeslotList', array(
                'eventId' => $eventId,
                'bookableId' => $bookableId,
                'model' => $model,
                'form' => $form
            ));
            $control1->render();
            ?>  
        </div>
        <div class="tab-pane" id="tab4" style="min-height: 380px;margin-right:2px;">                
            <?php
            $control2 = new BUIControl('priceAdjust');
            $control2->addRenderView('roleList','bookable_list_priceAdjust', array(
                'eventId' => $eventId,
                'bookableId' => $bookableId,
                'model' => $model,
                'form' => $form
            ));
            $control2->render();
            ?>  
        </div>
        <div class="tab-pane" id="tab5" style="min-height: 380px;margin-right:2px;">                
            <?php
            $control->renderView('bookable_add_other', array(
                'eventId' => $eventId,
                'bookableId' => $bookableId,
                'model' => $model,
                'form' => $form
            ));
            ?>  
        </div>
    </div>
</div>
<?php $this->endWidget(); ?>
<button class="btn" onclick="javascript:saveBookable()"><?php echo $saveStr;?></button>